/**
 * 
 */
package classe;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;



/**
 * @author guispeed4262
 *
 */
public class Devis  implements Comparable <Devis> {
	private Date dateDeb,dateFin;
	private static int num=0,numAnnee=1;
	private int id,idAnnee;
	private ArrayList <Poste> poste;
	private double total;
	private String reference;
	private boolean valider,hist;
	private int idClient,numListe;
	
	@SuppressWarnings("deprecation")
	public Devis(int idClient,ArrayList <Poste> poste,String reference,Date dateDeb,Date dateFin){
		this.poste= new ArrayList <Poste>();
		this.poste.addAll(poste);
		this.valider=false;
		this.reference=reference;		
		this.numAnnee++;
		this.id=this.num;
		this.idAnnee=this.numAnnee;
		this.idClient=idClient;
		this.numListe=num;
		this.num++;
		this.hist=false;
		this.dateDeb=dateDeb;
		this.dateFin=dateFin;
		System.out.println(dateDeb.toString());
	}
	public static String getNouvRef(){
		String str=""+Calendar.getInstance().get(Calendar.YEAR);
		str=str.substring(2,4);
		if(getNumAnnee() < 10){
			return str+"-0"+getNumAnnee();
		}else
		{
		return str+"-"+getNumAnnee();
		}
	}
	public int getIdAnnee() {
		return idAnnee;
	}
	public static int getNumAnnee() {
		return numAnnee;
	}
	public int getIdClient() {
		return idClient;
	}
	public String getReference() {
		return reference;
	}
	public Poste getPoste(int nbr){
		return poste.get(nbr);
	}

	public int getNbrPoste() {
		return poste.size();
	}
	public boolean isValider() {
		return valider;
	}
	public void setValider(boolean valider) {
		this.valider = valider;
	}
	public void ChangeValider() {
		if(valider==true){
			valider=false;
		}else 
			valider=true;
	}
	public void ChangeHist() {
		if(hist==true){
			hist=false;
		}else 
			hist=true;
	}
	public int getNumListe() {
		return numListe;
	}
	
	public void setNumListe(int numListe) {
		this.numListe = numListe;
	}
	public double getTotalTTC(){
		double total=0.0;
		for(int i=0;i<poste.size();i++){
			total+=poste.get(i).getMontantTTC();
		}
		return total;
	}
	public ArrayList<Poste> getListePoste() {
		return poste;
	}
	public boolean isHist() {
		return hist;
	}
	public void setHist(boolean hist) {
		this.hist = hist;
	}
	public Date getDateFin() {
		return dateFin;
	}
	public String getDateDebStr() {
		//System.out.println("deb "+dateDeb.toString());
		return dateDeb.getDay()+"/"+dateDeb.getMonth()+"/"+dateDeb.getYear();
	}
	public String getDateFinStr() {
		/*
		System.out.println("fin "+dateFin.toString());
		System.out.println("fin "+dateFin.getDay()+"/"+dateFin.getMonth()+"/"+dateFin.getYear());
		dateFin.setYear(2010);
		System.out.println("+fin "+dateFin.toString());
		System.out.println("+fin "+dateFin.getDay()+"/"+dateFin.getMonth()+"/"+dateFin.getYear());
		*/
		return dateFin.getDay()+"/"+dateFin.getMonth()+"/"+dateFin.getYear();
		
	}
	public String tempsRestant(){
		GregorianCalendar calendar = new GregorianCalendar();
		int jour=calendar.get(Calendar.DAY_OF_MONTH)-dateFin.getDay();
		int mois=calendar.get(Calendar.MONTH)-dateFin.getMonth();
		int annee=calendar.get(Calendar.YEAR)-dateFin.getYear();
		if(annee==0){
			if(mois==0){
				return ""+jour+"jours";
			}else{
				return ""+mois+"mois et "+jour+"jours";
			}
		}else return "IMPOSSIBLE";
	}
	public int compareTo(Devis dev){
		//if (this.reference.compareTo(dev.reference) ==0){
		System.out.println(this.reference.compareTo(dev.reference));
			return this.reference.compareTo(dev.reference);
		/*
		}else {
			return this.idClient.compareTo (dev.idClient);
		}
		*/
	}
	
}
